<template>
  <div class="welcome-container">
    <el-row :gutter="20">
      <!-- 欢迎卡片 -->
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <el-card class="welcome-card">
          <div class="welcome-header">
            <img src="@/assets/welcome.svg" alt="welcome" class="welcome-img">
            <div class="welcome-info">
              <h2>欢迎使用汽车租赁管理系统</h2>
              <p>{{ greeting }}，{{ userInfo.username || '管理员' }}！祝您工作愉快。</p>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <!-- 数据统计卡片 -->
      <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6" v-for="(item, index) in statsList" :key="index">
        <el-card class="stats-card" :body-style="{ padding: '20px' }">
          <div class="stats-header">
            <div class="stats-title">{{ item.title }}</div>
            <div class="stats-icon" :style="{ backgroundColor: item.color }">
              <i :class="item.icon"></i>
            </div>
          </div>
          <div class="stats-number">{{ item.number }}</div>
          <div class="stats-footer">
            <span>{{ item.desc }}</span>
            <el-button type="text" @click="navigateTo(item.path)">查看详情 <i class="el-icon-arrow-right"></i></el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>
    
    <!-- 图表区域 -->
    <el-row :gutter="20" style="margin-top: 20px;">
      <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
        <el-card>
          <div slot="header" class="clearfix">
            <span>订单统计</span>
          </div>
          <div class="chart-placeholder">
            <i class="el-icon-data-analysis"></i>
            <p>订单数据图表将在此显示</p>
          </div>
        </el-card>
      </el-col>
      
      <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
        <el-card>
          <div slot="header" class="clearfix">
            <span>车辆使用率</span>
          </div>
          <div class="chart-placeholder">
            <i class="el-icon-data-line"></i>
            <p>车辆使用率图表将在此显示</p>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'Welcome',
  data() {
    return {
      statsList: [
        {
          title: '车辆总数',
          number: 126,
          desc: '系统中的车辆总数',
          color: '#40c9c6',
          icon: 'el-icon-truck',
          path: '/vehicles'
        },
        {
          title: '今日订单',
          number: 18,
          desc: '今日新增订单数',
          color: '#36a3f7',
          icon: 'el-icon-s-order',
          path: '/orders'
        },
        {
          title: '用户总数',
          number: 258,
          desc: '注册用户总数',
          color: '#f4516c',
          icon: 'el-icon-user',
          path: '/users'
        },
        {
          title: '门店数量',
          number: 12,
          desc: '全部门店数量',
          color: '#34bfa3',
          icon: 'el-icon-office-building',
          path: '/stores'
        }
      ]
    }
  },
  computed: {
    ...mapGetters(['userInfo']),
    greeting() {
      const hour = new Date().getHours()
      if (hour < 6) return '凌晨好'
      if (hour < 9) return '早上好'
      if (hour < 12) return '上午好'
      if (hour < 14) return '中午好'
      if (hour < 17) return '下午好'
      if (hour < 19) return '傍晚好'
      if (hour < 22) return '晚上好'
      return '夜深了'
    }
  },
  methods: {
    navigateTo(path) {
      this.$router.push(path)
    }
  }
}
</script>

<style lang="scss" scoped>
.welcome-container {
  padding-bottom: 20px;
  
  .welcome-card {
    margin-bottom: 20px;
    
    .welcome-header {
      display: flex;
      align-items: center;
      
      .welcome-img {
        width: 120px;
        height: 120px;
        margin-right: 20px;
      }
      
      .welcome-info {
        h2 {
          margin-top: 0;
          margin-bottom: 10px;
          font-weight: 500;
          color: #303133;
        }
        
        p {
          margin: 0;
          font-size: 16px;
          color: #606266;
        }
      }
    }
  }
  
  .stats-card {
    height: 150px;
    margin-bottom: 20px;
    
    .stats-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 15px;
      
      .stats-title {
        font-size: 16px;
        color: #606266;
      }
      
      .stats-icon {
        width: 48px;
        height: 48px;
        border-radius: 8px;
        display: flex;
        justify-content: center;
        align-items: center;
        
        i {
          font-size: 24px;
          color: #fff;
        }
      }
    }
    
    .stats-number {
      font-size: 28px;
      font-weight: bold;
      color: #303133;
      margin-bottom: 15px;
    }
    
    .stats-footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #909399;
      font-size: 14px;
    }
  }
  
  .chart-placeholder {
    height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #909399;
    
    i {
      font-size: 48px;
      margin-bottom: 10px;
    }
  }
}

/* 响应式调整 */
@media screen and (max-width: 768px) {
  .welcome-container {
    .welcome-card {
      .welcome-header {
        flex-direction: column;
        text-align: center;
        
        .welcome-img {
          margin-right: 0;
          margin-bottom: 15px;
        }
      }
    }
  }
}
</style> 